<!--
  -    Copyright (c) 2018-2025, lengleng All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without
  - modification, are permitted provided that the following conditions are met:
  -
  - Redistributions of source code must retain the above copyright notice,
  - this list of conditions and the following disclaimer.
  - Redistributions in binary form must reproduce the above copyright
  - notice, this list of conditions and the following disclaimer in the
  - documentation and/or other materials provided with the distribution.
  - Neither the name of the pig4cloud.com developer nor the names of its
  - contributors may be used to endorse or promote products derived from
  - this software without specific prior written permission.
  - Author: lengleng (wangiegie@gmail.com)
  -->
<template>
  <div class="execution">
    <basic-container class="table-style">
      <avue-crud
        ref="crud"
        :page="page"
        :data="tableData"
        :permission="permissionList"
        :table-loading="tableLoading"
        :option="tableOption"
        @on-load="getList"
        @search-change="searchChange"
        @refresh-change="refreshChange"
        @size-change="sizeChange"
        @current-change="currentChange"
        @row-update="handleUpdate"
        @row-save="handleSave"
        @row-del="rowDel"
      >
        <template slot-scope="{ row, index, type, size }" slot="menu">
          <el-button :size="size" :type="type" icon="el-icon-view" @click.stop="showClick(row, index)">查看</el-button>
          <el-button :size="size" :type="type" icon="el-icon-view" @click.stop="restroePersonClick(row, index)">还原</el-button>
        </template>
        <template slot="surplusDays" slot-scope="scope">
            <span v-if="scope.row.personState == '21' || scope.row.personState == '22'">{{scope.row.surplusDays}}</span>
            <span v-else>--</span>
        </template>

         <template slot-scope="scope" slot="webCustomAddressSearch">
            <div>
              <el-cascader
                  clearable
                  filterable
                  v-model="customSearch.webCustomAddress"
                  :options="provinceCityList"
                  :props="{ checkStrictly: true }"
                  ></el-cascader>
            </div>
         </template>
      </avue-crud>
    </basic-container>
    <TotalInfo ref="totalInfo"></TotalInfo>

  </div>
</template>

<script>
  let moment = require('moment');
  import {formDataDowload} from '@/views/hotel/common/hotel-utils'
import mixinsCommon from '@/views/hotel/common/common-mixins.js';
import { trashList, restroePerson} from '@/views/hotel/api/hotel-management.js';
import { tableOption } from '@/views/hotel/const/crud/hotel-statistics';
import { mapGetters } from 'vuex';
import TotalInfo from '@/views/hotel/components/total-info.vue';

export default {
  name: 'jdglhotelhouseinfo',
  mixins: [mixinsCommon],
  components: {
    TotalInfo,
  },
  data() {
    return {
      hotels:[],
      selfListHotelList:[],
      addVisible:false,
      activeName: 'details',
      searchForm: {},
      customSearch:{
        webCustomAddress:[]
      },
      tableData: [],
      provinceCityList:[],
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10 // 每页显示多少条
      },
      tableLoading: false,
      tableOption: tableOption,
      dialogTableVisible: false,
      fromObj:{
        routes: [
          {
            flightNumber: ''
          }
        ]
      }
    };
  },
  watch:{

  },
  computed: {
    ...mapGetters(['permissions']),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permissions.personinfo_add, false),
        delBtn: this.vaildData(this.permissions.personinfo_del, false),
        editBtn: this.vaildData(this.permissions.personinfo_edit, false)
      };
    }
  },
  methods: {

    editClick(row,index,type){
      if(type == 'edit' || type == 'verify'){
        this.$refs.infoEdit.setData({},type,row.personId)
      }else if(type == 'leaveHotelInfo'){
        this.$refs.leaveHotelInfo.setData(row, true)
      }else if(type == 'hotelStayInfo'){
        this.$refs.hotelStayInfo.setData(row, true)
      }else if(type == 'stayDelayInfo'){
        this.$refs.stayDelayInfo.setData(row, true)
      }else if(type == 'stayInfoRecordEdit'){
        this.$refs.stayInfoRecordEdit.setData(row, true)
      }
    },
    successClose(){
      this.getList(this.page);
    },
    getList(page, params) {

      this.tableLoading = true;
      let search = {}
      for (let key in params) {
          if (key == 'moveStartTime') {
              search.moveStartTimeMin = params[key][0];
              search.moveStartTimeMax = params[key][1];
              delete params.moveStartTime;
          } else if (key == 'releaseIsolationDate') {
              search.releaseIsolationDateMin = params[key][0];
              search.releaseIsolationDateMax = params[key][1];
              delete params.releaseIsolationDate;
          }else if (key == 'leaveHotelDate') {
              search.leaveHotelDateMin = params[key][0];
              search.leaveHotelDateMax = params[key][1];
              delete params.leaveHotelDate;
          }
      }
      let webCustomAddress = this.customSearch.webCustomAddress

      if(webCustomAddress.length>0){
        search.nationProvince = webCustomAddress[0]|| '';
        search.nationCity = webCustomAddress[1]||'';
        search.nationDistrict = webCustomAddress[2]||'';
      }
      trashList(
        Object.assign(
          {
            current: page.currentPage,
            size: page.pageSize
          },
          params,
          this.searchForm,
          search
        )
      )
        .then(response => {
          response.data.data.records.map(item=>{
            item.hotelStreetId = item.hotelBaseInfoId;
            if(item.nationProvince && item.nationDistrict && item.nationCity){
              item.webCustomAddress = [item.nationProvince,item.nationCity,item.nationDistrict];
            }
          })
          this.tableData = response.data.data.records;
          this.page.total = response.data.data.total;
          this.tableLoading = false;
        })
        .catch(() => {
          this.tableLoading = false;
        });
    },
    rowDel: function(row, index) {
      this.$confirm('是否确认删除' + row.hotelName + '-' + row.roomFloor + '-' + row.roomNum, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(function() {
          return delObj(row.houseId);
        })
        .then(data => {
          this.$message.success('删除成功');
          this.getList(this.page);
        });
    },
    handleUpdate: function(row, index, done, loading) {
      putObj(row)
        .then(data => {
          this.$message.success('修改成功');
          done();
          this.getList(this.page);
        })
        .catch(() => {
          loading();
        });
    },
    handleSave: function(row, done, loading) {

      addObj(row)
        .then(data => {
          this.$message.success('添加成功');
          done();
          this.getList(this.page);
        })
        .catch(() => {
          loading();
        });
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    currentChange(current) {
      this.page.currentPage = current;
    },
    searchChange(form, done) {
       this.page.currentPage=1;
      this.searchForm = form;
      this.getList(this.page, form);
      done();
    },
    refreshChange() {
      this.getList(this.page);
    },
    restroePersonClick(row,index){
      this.$confirm(`是否确认恢复 ”${row.name}" 这条数据？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(()=> {
          restroePerson({
            personId:row.personId,
          }).then(data=>{
            this.$message.success('恢复成功');
            this.getList(this.page);
          },err=>{

          })
        })
        .then(data => {

        });
    },
    showClick(row, index) {
      this.$refs.totalInfo.setData({
        personId:row.personId,
        moveInfoId:row.moveInfoId,
        personState:row.personState,
        hotelBaseInfoId: row.hotelBaseInfoId
      },'geli')
    },
    async init() {
      // this.listHotelList = await this.listHotel({isSelf:'1'});
      let provinceCity = await this.getProvinceCity();
      this.provinceCityList = provinceCity;
      this.selfListHotelList = await this.listHotel({ isSelf: '1' });
      this.getDicts().then(data => {
        let obj = {
          isValid: 'is_valid',
          useType: 'use_type',
          roomState: 'room_state',
          belongto:'hotel_street',
          nucleinTestCase: 'nuclein_test_case',

          dataSource: 'data_source',
          riskLevel:'risk_level',
          personState:'person_state',

          isOverStudent: 'is_valid',
          isYjwLjs: 'is_valid',
          isHbfwhFsPerson: 'is_valid',
          isWhFsPerson: 'is_valid',
          isHaveBjLjs: 'is_valid',
          isAircrew: 'is_valid',
          isGravida: 'is_valid',
          isBodyDisease: 'is_valid',
          isBasicDisease: 'is_valid',
          isCriminalPerson: 'is_valid',
          isSpiritHeartExce: 'is_valid',
          isMourning: 'is_valid',
          isImmunity: 'is_valid'
        };
        this.tableOption.column.map(item => {
          if (obj[item.prop]) {
            if (data[obj[item.prop]]) {
              item.dicData = data[obj[item.prop]];
            }
          } else if (item.prop == 'hotelBaseInfoId') {
            item.dicData = this.selfListHotelList;
          }else if (item.prop == 'webCustomAddress') {
            item.dicData = provinceCity;
          }
        });

      });
    }
  },
  mounted(){

  },
  created() {
    if(this.$route.query.hotelBaseInfoId){
      this.searchForm.hotelBaseInfoId = this.$route.query.hotelBaseInfoId
    }
    this.init();

  }
};
</script>

<style>
.custom-style.avue-detail {
  padding-top: 0px;
}
.custom-divider.el-divider--horizontal {
  margin: 10px 0px 0px;
}

</style>
